package com.ruoyi.keep.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.keep.domain.MntApp;
import com.ruoyi.keep.service.IMntAppService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 应用管理Controller
 *
 * @author ruoyi
 * @date 2020-09-27
 */
@RestController
@RequestMapping("/keep/app")
public class MntAppController extends BaseController {
    @Autowired
    private IMntAppService mntAppService;

    /**
     * 查询应用管理列表
     */
    @PreAuthorize("@ss.hasPermi('keep:app:list')")
    @GetMapping("/list")
    public TableDataInfo list(MntApp mntApp) {
        startPage();
        List<MntApp> list = mntAppService.selectMntAppList(mntApp);
        return getDataTable(list);
    }

    /**
     * 导出应用管理列表
     */
    @PreAuthorize("@ss.hasPermi('keep:app:export')")
    @Log(title = "应用管理" , businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MntApp mntApp) {
        List<MntApp> list = mntAppService.selectMntAppList(mntApp);
        ExcelUtil<MntApp> util = new ExcelUtil<MntApp>(MntApp. class);
        return util.exportExcel(list, "app");
    }

    /**
     * 获取应用管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('keep:app:query')")
    @GetMapping(value = "/{appId}")
    public AjaxResult getInfo(@PathVariable("appId") Long appId) {
        return AjaxResult.success(mntAppService.selectMntAppById(appId));
    }

    /**
     * 新增应用管理
     */
    @PreAuthorize("@ss.hasPermi('keep:app:add')")
    @Log(title = "应用管理" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MntApp mntApp) {
        return toAjax(mntAppService.insertMntApp(mntApp));
    }

    /**
     * 修改应用管理
     */
    @PreAuthorize("@ss.hasPermi('keep:app:edit')")
    @Log(title = "应用管理" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MntApp mntApp) {
        return toAjax(mntAppService.updateMntApp(mntApp));
    }

    /**
     * 删除应用管理
     */
    @PreAuthorize("@ss.hasPermi('keep:app:remove')")
    @Log(title = "应用管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{appIds}")
    public AjaxResult remove(@PathVariable Long[] appIds) {
        return toAjax(mntAppService.deleteMntAppByIds(appIds));
    }
}
